<template>
  <div>
    <h3>购物车页面</h3>
    <ul>
      <li
        v-for="(item, index) in products"
        :key="index"
      >
        {{ item.title }}-{{ item.price }}--{{ item.inventory }}
        <button
          :disabled="!item.inventory"
          @click="addCar(item)"
        >
          加入购物车
        </button>
      </li>
    </ul>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";

export default {
  data() {
    return {};
  },
  methods: {
    ...mapActions("shop", ["getData"]),
    ...mapActions("car", ["addCar"]),
  },
  computed: {
    ...mapState("shop", ["products"]),
  },
  mounted() {
    this.getData();
  },
};
</script>

<style scoped></style>
